<?php if(!defined('IN_JOSEPPE')) { exit('Access Denied'); } ?>
<?php include_once S_ROOT.'admin/header.php'; ?>
<?php include_once S_ROOT.'admin/menu.php'; ?>
		<div style="margin:0 auto;width:980px;">
			<div id="bd">
				<form action="admin.php" method="post">
					<div class="wrap">
						<p class="title">类别管理</p>
							<p>
							<label>增加一个类</label><input type="text" name="add_name" />
							<label>上级类</label><select name="add_rootid"><option value="0">根类</option><?php foreach($types as $type){ if($type['rootid'] == 0){ ?><option value="<?php echo $type['id']?>"><?php echo $type['name']; ?></option><?php } } ?></select>
							</p>
							<?php if(!empty($types)){ ?>
							<p>
							<label>修改一个类</label><select name="old_name" onchange="document.getElementById('edit_name').value = this.value;"><?php foreach($types as $type){ ?><option value="<?php echo $type['name']?>"><?php echo $type['rootid']?'--'.$type['name']:$type['name']; ?></option><?php } ?></select><input type="text" id="edit_name" name="edit_name" value="<?php echo $types[0]['name']; ?>"/>
							<label>上级类</label><select name="edit_rootid"><option value="0">根类</option><?php foreach($types as $type){ if($type['rootid'] == 0){ ?><option value="<?php echo $type['id']?>"><?php echo $type['name']; ?></option><?php } } ?></select>
							</p>
							<?php } ?>
					</div><br/>
					<div class="wrap sec">
						<p class="title">产品维护</p>
							<div id="p_1">
							<?php $count = count($product); foreach($product as $key => $p){ ?>
							<?php if($key != 0 && $key%$pagesize == 0){ ?><div id="p_<?php echo $key/$pagesize + 1; ?>"><?php } ?>
							<p>
							<a href="admin.php?do=delproduct&id=<?php echo $p['id']; ?>">删除产品</a>
							<label>类别</label><select name="product[<?php echo $p['id']?>][typeid]"><?php foreach($types as $type){ ?><option value="<?php echo $type['id']?>" <?php if($p['typeid'] == $type['id']){ ?>selected="on"<?php } ?>><?php echo $type['rootid']?'--'.$type['name']:$type['name']; ?></option><?php } ?></select>
							<label>名称</label><input type="text" name="product[<?php echo $p['id']; ?>][name]" value="<?php echo $p['name']; ?>" />
							<label>序号</label><input type="text" name="product[<?php echo $p['id']; ?>][indexnum]" value="<?php echo $p['indexnum']; ?>" />
							<label>图片</label><?php if(isset($p['img'])){ foreach($p['img'] as $img){ ?><img src="<?php echo $img['img_small']; ?>" /><a href="admin.php?do=delimg&id=<?php echo $img['id']; ?>">删除图片</a><?php } }  else { ?><a href="admin.php?cp=uploadimg&pid=<?php echo $p['id']; ?>">上传图片</a><?php } ?>
							</p>
							<?php if( $key+1 != $count && ($key+1)%$pagesize == 0){ ?></div><?php } ?>
							<?php } ?>
							</div>
							<script text="text/javascript">
							var showid = 1;
							var suzu = Array(<?php foreach($product as $key => $p){ if($key%$pagesize == 0) { if($key != 0) echo ","; echo $key/$pagesize + 1; } }?>);
							var len = suzu.length;
							function show(id){
								if(len){
									for (var i = 0; i < len ; i++ )
									{
										if(id == suzu[i]){
											showid = id;
											document.getElementById('p_'+suzu[i]).style.display = "block";
										} else {
											document.getElementById('p_'+suzu[i]).style.display = "none";
										}
									}
								}
							}
							function pre(){
								if(showid-1 > 0){
									showid--;
									if(len){
										for (var i = 0; i < len ; i++ )
										{
											if(showid == suzu[i]){
												document.getElementById('p_'+suzu[i]).style.display = "block";
											} else {
												document.getElementById('p_'+suzu[i]).style.display = "none";
											}
										}
									}
								}
							}
							function next(){
								if(showid+1 < len){
									showid++;
									if(len){
										for (var i = 0; i < len ; i++ )
										{
											if(showid == suzu[i]){
												document.getElementById('p_'+suzu[i]).style.display = "block";
											} else {
												document.getElementById('p_'+suzu[i]).style.display = "none";
											}
										}
									}
								}
							}
							show(1);
							</script>
							<p id="paging" class="meneame"><a href="javascript:pre();">上一页</a> <?php foreach($product as $key => $p){ if($key%$pagesize == 0){ ?><a href="javascript:show('<?php echo $key/$pagesize + 1; ?>')"><?php echo $key/$pagesize + 1; ?></a> <?php } } ?><a href="javascript:next();">下一页</a></p>
					</div><br/>
					<div class="wrap">
						<p class="title">增加产品</p>
							<p>
							<label>类别</label><select name="typeid"><?php foreach($types as $type){ ?><option value="<?php echo $type['id']?>"><?php echo $type['rootid']?'--'.$type['name']:$type['name']; ?></option><?php } ?></select>
							<label>名称</label><input type="text" name="product_name" value="" />
							<label>序号</label><input type="text" name="product_indexnum" value="" />
							</p>
					</div><br/>
					<input type="hidden" name="action" value="product" />
					<input class="submit" type="submit" name="submit" value="提交" />
				</form>
			</div>
		</div>
    </body>
</html>